<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ include file="/commons/jsp/taglibs.jsp"%>
<OBJECT style="width: 0%; height: 0%;" classid="clsid:2B92874C-DCA6-4641-AEA5-BAEDE459B41C" height="0" width="0" size="0" id="CMSSign" name="CMSSign"></OBJECT>
<title>政府网上采购管理系统</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<link href="${ctx}/commons/css/login_css.css" rel="stylesheet"/>
	<link rel="shortcut icon" href="${ctx }/website/homepage/favicon.ico"> 
	<link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/default/easyui.css"/>
	<!-- jqueryUI JS文件的引入 -->
	<script type="text/javascript" src="${ctx}/commons/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="${ctx}/commons/js/jquery.easyui.min.js"></script>
	<!-- easyUI验证扩展，增加自定义验证, 一定要放在最后-->
	<script type="text/javascript" src="${ctx}/commons/js/easyui-extends-validate.js"></script>
	<!-- 开发国际化的引用，主要完成后台信息在前台提示的国际化，一定要放在最后 -->
	<script type="text/javascript">var ctx = '${ctx}';var actionExt = "action";var i18n = new Object();</script>
	<script src="${ctx}/commons/js/i18n/message_zh_CN.js" type="text/javascript"></script>
	<script type="text/javascript">
		$(function(){
			var h = $(window).height();
			var autoH = (h-400)/2;
			$("#login_table").css("margin-top",autoH + "px");
			$("#login_page").show();
			$(window).keydown(function(event){
				if(event.keyCode==13){
					$("#okBtn").click();
				}
			});
			$("#okBtn").click(function(){
				clientsign();
			});
			//给用户名输入框绑定样式和验证条件
			$('#pin').validatebox({
				required: true,
				validType:['isNull','unsafe'],
				missingMessage:'请输入PIN码！'
			});
			$("#pin").focus();
		});

		function SelectCert() {
			var sMsg = "";
			var AlgoProvider="RSA";
		    var AlgoProvider = "P11";
		    var bRet = CMSSign.Initialize(AlgoProvider,$('#pin').val());
			if (!bRet) {
				$.messager.alert('提示','控件初始化失败!','warning');
				return false;
			}	
			//签名
			bRet = CMSSign.Sign("<%=session.getId()%>");
			if (bRet) {
				$('#SIGN_DATA').val(CMSSign.SignedData);
			} else {
				return false;
			}
			//取证书信息
			var strClientCert = CMSSign.GetCertEx(2);
			$('#CERT_DATA').val(strClientCert);
			var clientCajgdm = CMSSign.GetCertInfo(strClientCert, 2007, '');
			if('AHCARSA' != clientCajgdm){
				$.messager.alert('提示','插入的不是安徽ca发的KEY!','warning');
			}
			var caName = CMSSign.GetCertInfo(strClientCert, 3007, '');
			rs = CMSSign.VerifyCert(strClientCert);
			if(!rs){
				$.messager.alert('提示','证书有效性验证异常!','warning');
				return;
			}
			//3.4剩余天数提醒
			rs = CMSSign.GetCertInfo(strClientCert, 3043, '');
			if('' == rs) {
				$.messager.alert('提示','剩余天数获取异常!','warning');
				return;
			}
			if(rs<=45)
				$.messager.alert('提示','您的数字证书将于'+rs+'天后过期，请及时升级数字证书!','warning');
			if(rs<=0){
				$.messager.alert('提示','您的数字证书已过期，请升级数字证书后再登录系统!','warning');
				return;
			}
			$('#caCard').val(caName);
		    return true;
		}
		 
		function clientsign()
		{
			if(!$('#loginForm').form('validate')){
				return false;
			}
			if(!SelectCert()){
				$.messager.alert('提示','取证书PEM失败!','warning');
				return false;
			}
			$('#okBtn').attr("disabled", "disabled");
			$.ajax({
				type: "post",
				timeout:300000,
				url:  "${ctx}/user-login-sys-new/calogin",
				data: {signData:$('#SIGN_DATA').val(),certData:$('#CERT_DATA').val(),caCard:$('#caCard').val()},
				success: function(String){
					if(String == 'registerUnAuditPass'){
						window.location.href = "${ctx}/user-login-sys-new/unPassRegisterInfo";//审核不通过或未审核
					}else if(String == 'userLoginSuccess'){//验证成功，登录
						window.location.href = "${ctx}/portal/index.jsp";
					}else{
					    if(String == 'userNoExist'){
						$.messager.alert('提示','此用户不存在!','warning');
					    }
					    if(String == '请求签名服务器失败！'){
						$.messager.alert('提示','请求签名服务器失败！','warning');
					    }
						$.messager.alert('提示',data,'info');
						$('#okBtn').attr("disabled", false);
						$("#pin").focus();
					}
				},
				error: function(res){
					$('#okBtn').removeAttr("disabled");
					$.messager.alert('提示',res.responseText,'warning');
					$("#pin").focus();
				}
			});
		}
		
		 function changeToPWD(){
		   window.location = "${ctx}/user-login-sys-new/loginPwd";
		 }
	</script>
</head>

<body>
<center id="login_page" style="display: none;">
	<form action="${ctx}/user-login-sys/calogin" id="loginForm" method="post" >
	<input type="hidden" name="caCard" id="caCard"/>
	<input type="hidden" name="signData" id="SIGN_DATA"/>
	<input type="hidden" name="certData" id="CERT_DATA"/>
  <table width="530" id="login_table" height="320" border="0px" cellspacing="0" cellpadding="0" background="../commons/images/login/table_bg.png">
    <tbody>
    <tr>
      <td colspan="2" width="70%" height="70" style="padding-top: 25px;padding-left: 30px;" align="left" valign="top"><img src="../commons/images/login/logo2.png" alt="" width="350" height="56"></td>
    </tr>	
    <tr>
      <td style="width:50%;height:90px" align="right">  
            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PIN码：<input type="password" name="pin" id="pin" ><label for="textfield"></label></span> 
      </td>
      <td  rowspan="2" align="left" width="25%" >
      <br></br>
  
        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><a href="javascript:void(0)" onclick="changeToPWD()" style="text-decoration:none;"><img src="${ctx}/commons/images/switch.png" border="0" width="50px"/><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密码登录</br></a>
      </td>
    </tr>
    <tr>
	      <td  height="60px" align="center">
		      <div class="submit"  >
		        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);"><img src="${ctx}/commons/images/login/submit.png" alt="C A 登 录" title="C A 登 录" border="0" id="okBtn" /></a></span>
		      </div>
		     
	      </td>
    </tr>
    <tr>
      <td colspan="2" height="80">&nbsp;</td>
    </tr>
  </tbody>
  </table>
  </form>
  <p>&nbsp;</p>
<table width="80%" border="0" cellspacing="0" style="letter-spacing: 2px;line-height: 20px;" cellpadding="0">
  <tbody><tr>
    <td align="center" valign="middle"><div id="footer">
      <p>主办单位：包河区政府采购中心　　联系电话：0551-63357535</p>
<a href="${ctx}/file_resource/Active.zip">控件驱动下载（请使用IE8以上版本浏览器登录）</a> 联系地址：包河区政务服务中心3楼</p>
    </div></td>
  </tr>
</tbody></table>
</center>
</body>
</html>
